TOP_NAME := top
 
VSRCS = $(shell find $(./vsrc ) -name "*.v")
CSRCS = $(shell find $(./csrc ) -name "*.c" -or -name "*.cc" -or -name "*.cpp")
 


OBJ_DIR 		= ./obj_dir

INCLUDE 		= ./csrc/include
LDFLAGS			+= -lreadline -lSDL2 -ldl
DIFFTEST		:= $(NEMU_HOME)/build/riscv32-nemu-interpreter-so

sim: clean
	$(call git_commit, "sim RTL") # DO NOT REMOVE THIS LINE!!!
	verilator --trace --cc --exe --build \
    	--top-module top \
    	-I$(INCLUDE) ./csrc/main.cpp $(VSRCS) $(CSRCS) \
	-LDFLAGS -lSDL2 -LDFLAGS -lreadline

RUN_FLAGS	:= --img=${IMG} --elf=${ELF} --diff=${DIFFTEST}
BIN		:= obj_dir/V$(TOP_NAME)
NPC_EXEC	:= ${BIN} ${RUN_FLAGS}

run: sim
	$(call git_commit, "run NPC")
	@${NPC_EXEC}

wave: run
	gtkwave wave.vcd
 
clean:
	rm -rf ${OBJ_DIR}

.PHONY:sim run wave clean
 
